package com.group.finance.controller;


import com.group.commons.util.ResponseInfo;
import com.group.commons.util.ResponseStatus;
import com.group.finance.entity.Deal;
import com.group.finance.service.impl.DealServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  交易记录
 * </p>
 *
 * @author zgc
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/deal")
public class DealController {

    @Resource
    private DealServiceImpl dealService;

    //增加交易记录
    @PostMapping("/add")
    public ResponseInfo addDeal(@RequestBody Deal deal) {

        Integer integer = dealService.addDeal(deal);

        ResponseInfo<Object> objectResponseInfo = new ResponseInfo<>();
        if (integer == null) {
            objectResponseInfo.setCode(500);
            objectResponseInfo.setMessage("增加失败");
            objectResponseInfo.setStatus(ResponseStatus.FAILED);
            return objectResponseInfo;
        }
        objectResponseInfo.setCode(200);
        objectResponseInfo.setMessage("完成增加");
        objectResponseInfo.setStatus(ResponseStatus.SUCCESS);
        return objectResponseInfo;
    }

    //查询所有成交交易记录
    @GetMapping("/succeedDeal/{current}/{size}")
    public ResponseInfo findSucceedDeal(@PathVariable("current") int current, @PathVariable("size") int size){

        List<Deal> list = dealService.findSucceedDeal(current, size,"成功");
        ResponseInfo<Object> objectResponseInfo = new ResponseInfo<>();
        objectResponseInfo.setData(list);
        objectResponseInfo.setCode(200);
        objectResponseInfo.setMessage("返回成交的交易记录");
        objectResponseInfo.setStatus(ResponseStatus.SUCCESS);
        return objectResponseInfo;
    }

    //查询所有失败的交易记录
    @RequestMapping("/FailDeal/{current}/{size}")
    public ResponseInfo findFailDeal(@PathVariable("current") int current, @PathVariable("size") int size){

        List<Deal> list = dealService.findSucceedDeal(current, size,"成功");

        ResponseInfo<Object> objectResponseInfo = new ResponseInfo<>();
        objectResponseInfo.setData(list);
        objectResponseInfo.setCode(200);
        objectResponseInfo.setMessage("返回失败的交易记录");
        objectResponseInfo.setStatus(ResponseStatus.SUCCESS);
        return objectResponseInfo;
    }

}
